//
//  YDYNewFeatureViewController.m
//  DY_Weibo3
//
//  Created by 杨德勇 on 2016/8/21.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYNewFeatureViewController.h"
#import "YDYNewFeatureCollectionViewCell.h"
@interface YDYNewFeatureViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation YDYNewFeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupCollectionView];
}
-(void)setupCollectionView{
    self.collectionView.pagingEnabled = YES;
    self.collectionView.bounces = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([YDYNewFeatureCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:@"newfeature"];
}



#pragma mark -
#pragma mark -collection datasource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    YDYNewFeatureCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"newfeature" forIndexPath:indexPath];
    cell.imgIndex = indexPath.item;
    
    return cell;
}

#pragma mark -
#pragma mark -collectionview delegate
-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
    
    YDYNewFeatureCollectionViewCell *visCell = collectionView.visibleCells.lastObject;
    //这个方法是返回刚刚消失的cell，所以item==2的时候显示的是第4张图
    if (indexPath.item == 2) {
        [visCell startAnimation];
    }
    
}
@end
